<?php

namespace App\Repository\Models;

use Illuminate\Database\Eloquent\Model;
use Prettus\Repository\Contracts\Transformable;
use Prettus\Repository\Traits\TransformableTrait;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
 * Class UserImRecord.
 *
 * @package namespace App\Repository\Models;
 */
class UserImRecord extends Model implements Transformable
{
    use TransformableTrait;
    use SoftDeletes;

    protected $table = 'user_im_record';
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = ['im_id_a','im_id_b','content','created_at','updated_at'];

    protected $appends = ['content_arr'];

    /**
     * 处理 content 聊天内容 json 格式转数组
     * */
    public function getContentArrAttribute()
    {
        $return = json_decode($this->content,1);
        rsort($return);
        return $return;
    }
}
